package test.yeahwap;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
public class Test {
	public static void main(String[] args) {
		BufferedReader br = null;
		BufferedWriter pw = null;
		try {
			br = new BufferedReader(new InputStreamReader(new FileInputStream("phone.txt"), "UTF-8"));
			Set<Integer> lines=new HashSet<Integer>();
			String s = null;
			while ((s = br.readLine()) != null && !"".equals(s=s.trim())) {
				lines.add(Integer.parseInt(s));
			}
			Object[] ids=lines.toArray();
			Arrays.sort(ids);
			pw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("newphone.txt"), "UTF-8"));
			for(Object id:ids){
				pw.write(id+"");
				pw.newLine();
			}
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (pw != null)
				try {
					pw.close();//先关pw
				} catch (IOException e) {
					e.printStackTrace();
				}
			if (br != null) {
				try {
					br.close();//后关br
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
}
